package com.smap.layer;

public class GoogleLayer extends GridLayer {
	public static final int BLANK = -1;
	public static final int OSM = 0;
	public static final int G_STREET = 1;
	public static final int G_SATELLITE = 2;
	public static final int G_HYBIRD = 3;
	public static final int G_ROAD = 10;

	public int type = 0;

	public GoogleLayer() {
		super();
		double originShift = 2 * Math.PI * 6378137 / 2.0;
		this.minX = originShift;
		this.minY = originShift;
	}

	@Override
	public void setUrl(Tile tile) {
		int x = tile.x;
		int y = (int) ((Math.pow(2, tile.z) - 1) - tile.y);
		int z = tile.z;

		int r = 0;
		String url = null;
		if (type == G_STREET) {// google normal;
			String t = "m";// m,h
			url = "http://mt" + r + ".google.com/vt/lyrs=" + t
					+ "@157000000&hl=en&x=" + x + "&y=" + y + "&z=" + z
					+ "&s=Gal";

		} else if (type == G_SATELLITE) {// satellite
			url = "http://khm" + r + ".google.com.au/kh/v=88&x=" + x + "&y="
					+ y + "&z=" + z + "&s=Gal";

		} else if (type == G_ROAD) {// google road
			String t = "h";// m,h
			url = "http://mt" + r + ".google.com/vt/lyrs=" + t
					+ "@157000000&hl=en&x=" + x + "&y=" + y + "&z=" + z
					+ "&s=Gal";

		} else if (type == G_HYBIRD) {// hybird
			/*
			 * url = "http://khm" + r + ".google.com.au/kh/v=88&x=" + x + "&y="
			 * + y + "&z=" + z + "&s=Gal";
			 * 
			 * String t = "h";// m,h url = "http://mt" + r +
			 * ".google.com/vt/lyrs=" + t + "@157000000&hl=en&x=" + x + "&y=" +
			 * y + "&z=" + z + "&s=Gal"; urls.add(url);
			 */
		} else if (type == OSM) {// OSM
			url = "http://b.tile.openstreetmap.org/" + z + "/" + x + "/" + y
					+ ".png";
		}

		tile.imageUrl = url;
	}

	@Override
	public void setType(Integer index) {
		if (index != null) {
			this.type = index;
		} else {
			this.type++;
			if (this.type > 2) {
				this.type = -1;
			}
		}
	} 
	
}
